﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Models.WebSite_HaiSheng;
using Telerik.Web.Mvc;
using Models;

namespace Utilities
{
    public class CT
    {
        public static GridModel GetViewModel<M, V>(Func<M, bool> filters, params string[] properties)
            where M : EntityBase
            where V : ViewBase
        {
            var data = CH.GetAllData<M>(filters, properties);
            var list = new List<V>();
            data.ForEach(d =>
            {
                V view = (V)Activator.CreateInstance(typeof(V), d);
                list.Add(view);
            });
            return new GridModel(list);
        }

        public static GridModel GetViewModel<M, V>(params string[] properties)
            where M : EntityBase
            where V : ViewBase
        {
            return GetViewModel<M, V>(null, properties);
        }

        public static GridModel GetViewModel<M>(Func<M, bool> filters, params string[] properties)
            where M : EntityBase
        {
            var data = CH.GetAllData<M>(filters, properties);
            return new GridModel(data);
        }

        public static GridModel GetViewModel<M>(params string[] properties)
            where M : EntityBase
        {
            return GetViewModel<M>(null, properties);
        }
    }
}